home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Languages Suite
/
ProgramD2.iso
/
Borland
/
Borland C++ V5.02
/
32SNIPIT.PAK
/
OPTDBPAR.C
< prev
next >
Wrap
C/C++ Source or Header
|
1997-05-06
|
3KB
|
96 lines
// BDE32 3.x - (C) Copyright 1996 by Borland International
// optdbpar.c
#include "snipit.h"
//=====================================================================
// Function:
// OptionalDBParam();
//
// Description:
// This function shows how to use optional parameters
// with the DbiOpenDatabase function to set the USER NAME.
//=====================================================================
void
OptionalDBParam (void)
{
DBIResult rslt; // Return value from BDE Functions
hDBIDb hDb = 0; // Handle to the database
pCHAR Alias="IBLOCAL"; // Alias Name
pCHAR Driver="INTRBASE"; // Driver Type
pCHAR Password="TEST"; // Password
pCHAR UserName="test"; // User Name
pFLDDesc pfldDesc; // Field descriptor for optional
// parameters
UINT16 iFields; // Number of fields (optional
// parameters)
CHAR szTemp[100]; // Maximum length of the path
// in the configuration file
pCHAR szData; // Data to display
Screen("*** Using Optional Parameters with DbiOpenDatabase ***\r\n");
rslt = DbiInit(NULL);
if (ChkRslt(rslt, "Init") == DBIERR_NONE)
{
szData = (pCHAR) malloc(DBIMAXSCRECSIZE);
pfldDesc = (pFLDDesc) malloc(DBIMAXSCFIELDS * sizeof(FLDDesc));
if ((szData == NULL) || (pfldDesc == NULL))
{
Screen(" Error - Out of Memory!");
if (szData) free(szData);
if (pfldDesc) free(pfldDesc);
DbiExit();
Screen("\r\n*** End of Example ***");
return;
}
// Initialize the pfldDesc variable to all zeroes.
memset((void*) pfldDesc , 0, sizeof(FLDDesc) * DBIMAXSCFIELDS);
iFields = 1;
// Set the user name
sprintf(szTemp, "%s", UserName);
strcpy(&szData[0], szTemp);
// Set up the parameter descriptor
pfldDesc[0].iFldNum = 1;
pfldDesc[0].iLen = (UINT16)(strlen(&szData[0]) + 1);
pfldDesc[0].iUnits1 = DBIMAXSCFLDLEN - 1;
strcpy(pfldDesc[0].szName, "USER NAME");
// Open the database
rslt = DbiOpenDatabase(Alias, Driver, dbiREADWRITE,
dbiOPENSHARED, Password, iFields,
pfldDesc, (pBYTE) szData, &hDb);
// Get a handle to an IDAPI database (STANDARD database handle
// can be returned, but this is mainly used for SQL connections).
if (ChkRslt(rslt, "OpenDatabase") != DBIERR_NONE)
{
Screen(" Error - Need to have an 'IBTEST' alias defined,");
Screen(" as well as having the user name\r\n");
Screen(" 'test' defined with a password of 'TEST'...");
rslt = DbiExit();
Screen("\r\n*** End of Example ***");
ChkRslt(rslt, "Exit");
return;
}
else
{
Screen("\r\n Connection established... ***");
}
}
Screen("\r\n*** End of Example ***");
rslt = DbiCloseDatabase(&hDb);
ChkRslt(rslt, "CloseDatabase");
DbiExit();
return;
}